#ifndef _MUX_H_
#define _MUX_H_


/*
*/
template<typedef Object, int N>
class Mux
{
	private :
		//the select line used.
		BitPointer sel[N];
		//objects to be selected between
		Object** array;	
	public:
		Mux()
		{
			unsigned long int val = 1;
			unsigned long int i = 0;
			for(i = 0; i < N; i++)
				val = val*2;
			array = (Object**) malloc(sizeof(Object*)*val);
		}
		~Mux(){ free(array);  }
		unsigned long int getIndex()
		{
			unsigned long int val = 0;
			unsigned long int multiplier = 1;
			unsigned long int i =0;
			for(i = 0; i < N; i++)
			{
				val = val + multiplier * sel[i].getBit();
				multiplier = multiplier * 2;
			}
			return val;
		}
		Object* select(){ return array[getIndex()];}
		//used to set values.
		Object*& operator[](unsigned int i){ return array[i];}

};

#endif
